package com.ruoyi.system.service.impl;

import java.util.List;

import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.AppAttachmentMapper;
import com.ruoyi.system.domain.AppAttachment;
import com.ruoyi.system.service.IAppAttachmentService;

/**
 * 文件Service业务层处理
 *
 * @author ruoyi
 * @date 2023-02-28
 */
@Service
public class AppAttachmentServiceImpl implements IAppAttachmentService {
    @Autowired
    private AppAttachmentMapper appAttachmentMapper;

    /**
     * 查询文件
     *
     * @param id 文件主键
     * @return 文件
     */
    @Override
    public AppAttachment selectAppAttachmentById(Long id) {
        return appAttachmentMapper.selectAppAttachmentById(id);
    }

    /**
     * 查询文件列表
     *
     * @param appAttachment 文件
     * @return 文件
     */
    @Override
    public List<AppAttachment> selectAppAttachmentList(AppAttachment appAttachment) {
        return appAttachmentMapper.selectAppAttachmentList(appAttachment);
    }

    /**
     * 新增文件
     *
     * @param appAttachment 文件
     * @return 结果
     */
    @Override
    public int insertAppAttachment(AppAttachment appAttachment) {
        appAttachment.setCreateTime(DateUtils.getNowDate());
        return appAttachmentMapper.insertAppAttachment(appAttachment);
    }

    /**
     * 修改文件
     *
     * @param appAttachment 文件
     * @return 结果
     */
    @Override
    public int updateAppAttachment(AppAttachment appAttachment) {
        return appAttachmentMapper.updateAppAttachment(appAttachment);
    }

    /**
     * 批量删除文件
     *
     * @param ids 需要删除的文件主键
     * @return 结果
     */
    @Override
    public int deleteAppAttachmentByIds(Long[] ids) {
        return appAttachmentMapper.deleteAppAttachmentByIds(ids);
    }

    /**
     * 删除文件信息
     *
     * @param id 文件主键
     * @return 结果
     */
    @Override
    public int deleteAppAttachmentById(Long id) {
        return appAttachmentMapper.deleteAppAttachmentById(id);
    }

    @Override
    public AppAttachment getOneByFileMd5(String fileMd5) {
        AppAttachment appAttachment = new AppAttachment();
        appAttachment.setFileMd5(fileMd5);
        List<AppAttachment> list = appAttachmentMapper.selectAppAttachmentList(appAttachment);
        return list.size() > 0 ? list.get(0) : null;
    }
}
